<?php

class Corporate_model  extends CI_Model {
	
	private $tbl_data= 'DTS_CORPORATE';
	public function __construct()
	{
		parent::__construct();
	}
	function list_all($fccode,$fcname){
		//$this->db->order_by('id','asc');
		$sql=" where 1=1 ";
		if ($fccode)
		{
			$sql.=" and fccode like '".$fccode."%'";
		}
		if ($fcname)
		{
			$sql.=" and fcname like '%".$fcname."%'";
		}
		//echo "select * from corporate ".$sql;
		return "select * from DTS_CORPORATE ".$sql;
	}

	function count_all(){
		return $this->db->count_all($this->tbl_data);
	}
	
	function get_by_id($fccode){
		$this->db->where('fccode', $fccode);
		return $this->db->get($this->tbl_data)->row();	    
	}

	
	function get_all(){
		$sql="SELECT B.FCCODE,B.FCCODE+' ['+B.FCNAME+']' FCNAME FROM DTS_CORPORATE B ORDER BY FCNAME";
		return $this->db->query($sql)->result_array();
	}
	
 	function get_corp_user($username){
		$sql="SELECT B.FCCODE,B.FCCODE+' ['+B.FCNAME+']' FCNAME FROM  ACL_USER_CORPORATE A
			  INNER JOIN  DTS_CORPORATE B ON A.FCCODE=B.FCCODE WHERE A.USERNAME='".$username."' order by b.fccode";
		return $this->db->query($sql)->result_array();        
	}	
}
?>